﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestProject1.MainClasses;


namespace TestProject1
{
    [TestClass]
    public class TestTicket
    {
        private IList<Tickets> TicketList = new List<Tickets>();
        public IList<User> TicUserList = new List<User>();
        private IList<Role> TicRoleList = new List<Role>();
        public IList<Customer> TicCustList = new List<Customer>();
        private IList<Category> TicCatList = new List<Category>();
        private IList<Departament> TicDepList = new List<Departament>();

        [TestMethod]
        public void TestMethodTicketInit()
        {   // Проверка инициализации заявок
            Tickets t = new Tickets();
            Assert.AreEqual(0, t.GetID());
            Assert.AreEqual("", t.GetStatus());
            Assert.AreEqual("", t.GetDD());
            Assert.AreEqual("", t.GetDM());
            Assert.IsNull(t.GetEx());
            Assert.IsNull(t.GetCat());
            Assert.IsNull(t.GetCust());
            Assert.IsNull(t.GetUser());
        }

        [TestMethod]
        public void TestMethodTicketAdd()
        {   // Проверка добавления одной заявки в список
            Customer cust = new Customer();
            TicCustList.Add(cust.add(11000, "name", "priority", "contacts"));
            Category cat = new Category();
            TicCatList.Add(cat.add(15001, "name"));
            Departament dep = new Departament();
            TicDepList.Add(dep.add(22221, "name", "status"));
            ///////////////////////
            Role r = new Role();
            TicRoleList.Add(r.add(104, "declarer", true, false, false, true, false, false));
            User usr = new User();
            TicUserList.Add(usr.add(222, "test", "test", "test", "test@gmail.com", 'm', r, dep));
            Tickets t = new Tickets();
            TicketList.Add(t.add(1, "28-09-12", "26-09-12", "done", usr, cust, cat));
            Assert.IsNotNull(TicketList.First().GetID());
            Assert.IsNotNull(TicketList.First().GetStatus());
            Assert.IsNotNull(TicketList.First().GetDD());
            Assert.IsNotNull(TicketList.First().GetDM());
            Assert.IsNotNull(TicketList.First().GetEx());
            Assert.IsNotNull(TicketList.First().GetCust());
            Assert.IsNotNull(TicketList.First().GetCat());
            Assert.IsNotNull(TicketList.First());
        }

        [TestMethod]
        public void TestMethodTicketEqualAdding()
        {   // Проверка правильного заполнения полей при добавлении заявки
            Customer cust = new Customer();
            TicCustList.Add(cust.add(11000, "name", "priority", "contacts"));
            Category cat = new Category();
            TicCatList.Add(cat.add(15001, "name"));
            Departament dep = new Departament();
            TicDepList.Add(dep.add(22221, "name", "status"));
            ///////////////////////
            Tickets t = new Tickets();
            int i = 1111;
            string s1 = "28-09-12";
            string s2 = "30-09-12";
            string s3 = "done";
            int u = 1001;
            User us = new User();
            Role r = new Role();
            TicRoleList.Add(r.add(104, "declarer", true, false, false, true, false, false));
            TicUserList.Add(us.add(222, "test1", "test1", "test1", "test1@gmail.com", 'm', r, dep));
            TicketList.Add(t.add(1, "20-09-12", "30-09-12", "not done", us, cust, cat));
            Assert.AreNotEqual(i, TicketList.First().GetID());
            Assert.AreNotEqual(s3, TicketList.First().GetStatus());
            Assert.AreEqual(s2, TicketList.First().GetDD());
            Assert.AreNotEqual(s1, TicketList.First().GetDM());
            //Assert.AreEqual(u,TicketList.First().GetEx());
        }

        [TestMethod]
        public void TestMethodTicketAddingToList()
        {   // Проверка добавления нескольких заявок в список     
            for (int i = 0; i < 3; i++)
            {
                Customer cust = new Customer();
                TicCustList.Add(cust.add(11000, "name", "priority", "contacts"));
                Category cat = new Category();
                TicCatList.Add(cat.add(15001, "name"));
                Departament dep = new Departament();
                TicDepList.Add(dep.add(22221, "name", "status"));
                /////////////////////////////
                Tickets t = new Tickets();
                User us = new User();
                Role r = new Role();
                TicRoleList.Add(r.add(104, "declarer", true, false, false, true, false, false));
                TicUserList.Add(us.add(222, "test2", "test2", "test2", "test2@gmail.com", 'm', r, dep));
                TicketList.Add(t.add(i + 1, "20-09-12", "30-09-12", "done", us, cust, cat));
                Assert.IsNotNull(TicketList.ElementAt(i));
            }
        }

        [TestMethod]
        public void TestMethodTicketEdit()
        {   //Проверка изменения полей заявки
            Customer cust = new Customer();
            TicCustList.Add(cust.add(11000, "name", "priority", "contacts"));
            Category cat = new Category();
            TicCatList.Add(cat.add(15001, "name"));
            Departament dep = new Departament();
            TicDepList.Add(dep.add(22221, "name", "status"));
            ////////////////////
            Tickets t = new Tickets();
            User us = new User();
            Role r = new Role();
            TicRoleList.Add(r.add(104, "declarer", true, false, false, true, false, false));
            TicUserList.Add(us.add(222, "test3", "test3", "test3", "test3@gmail.com", 'f', r, dep));
            TicketList.Add(t.add(1, "20-09-12", "30-09-12", "not done", us, cust, cat));
            int i = 1111;
            string s1 = "14-09-12";
            string s2 = "15-09-12";
            string s3 = "done";
            int u = 2222;
            TicketList.First().edit(i, s1, s2, s3, us, cust, cat);
            Assert.AreEqual(i, TicketList.First().GetID());
            Assert.AreEqual(s3, TicketList.First().GetStatus());
            Assert.AreEqual(s2, TicketList.First().GetDD());
            Assert.AreEqual(s1, TicketList.First().GetDM());
            //Assert.AreEqual(u, TicketList.First().GetEx());
        }

        [TestMethod]
        public void TestMethodTicketRemove()
        {   //Проверка удаления заявок из списка, которые имеют статус  "not done" 
            Customer cust = new Customer();
            TicCustList.Add(cust.add(11000, "name", "priority", "contacts"));
            Category cat = new Category();
            TicCatList.Add(cat.add(15001, "name"));
            Departament dep = new Departament();
            TicDepList.Add(dep.add(22221, "name", "status"));
            //////////////////////////
            Tickets t2 = new Tickets();
            User us = new User();
            Role r = new Role();
            TicRoleList.Add(r.add(104, "declarer", true, false, false, true, false, false));
            TicUserList.Add(us.add(222, "decler", "decler", "decler", "decler@gmail.com", 'm', r, dep));
            TicketList.Add(t2.add(2, "11-11-12", "-", "not done", us, cust, cat));
            Tickets t3 = new Tickets();
            TicketList.Add(t3.add(3, "30-10-12", "18-10-12", "done", us, cust, cat));
            Tickets t4 = new Tickets();
            TicketList.Add(t4.add(1, "20-09-12", "30-09-12", "not done", us, cust, cat));
            int cnt = TicketList.Count();
            for (int i = 0; i < TicketList.Count(); i++)
            {
                if (TicketList.ElementAt(i).GetStatus() == "not done")
                {
                    TicketList.RemoveAt(i); cnt--;
                }
                Assert.AreEqual(cnt, TicketList.Count());
            }
            for (int j = 0; j < TicketList.Count(); j++)
            {
                Assert.AreEqual("done", TicketList.ElementAt(j).GetStatus());
            }
        }


    }
}